package com.zs.framework.thread.volatiled;

/**
 * NoVisibility
 *
 * @author zhougf
 * @date 2020/09/03
 */
public class NoVisibility {
    private static boolean ready;
    private static int number;

    private static class ReaderThread extends Thread {
        @Override
        public void run() {
            while (!ready) {
                Thread.yield();
            }
            System.out.println(number);
        }
    }

    public static void main(String[] args) {
        number = 42;
        ready = true;
        for(int i = 100; i > 1; i--) {
            new ReaderThread().start();
        }
    }
}
